import 'package:flutter/material.dart';
import 'package:github_client_app/db/user_service.dart';
import 'package:github_client_app/models/user.dart';
import 'package:json_annotation/src/json_serializable.dart';

class DbPage extends StatefulWidget {
  const DbPage({Key? key}) : super(key: key);

  @override
  _DbPageState createState() => _DbPageState();
}

class _DbPageState extends State<DbPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("db")),
      body: Column(children: [
        ElevatedButton(
            onPressed: () async {
              UserService userService = UserService();
              User user = User();
              user.age = 82;
              user.name = "十大dou";
              user.keywords = "dfdaf";
              int i = await userService.insert(user);
              print(i);
            },
            child: const Text('增')),
        ElevatedButton(
            onPressed: () async {
              UserService userService = UserService();
              int i = await userService.delete({"name": "李四"});
              print(i);
            },
            child: const Text('删')),
        ElevatedButton(
            onPressed: () async {
              UserService userService = UserService();
              User user = User();
              user.age = 23;
              user.name = "王五";
              user.keywords = "dfd333af";
              int i = await userService.update({}, user);
              print(i);
            },
            child: const Text('改')),
        ElevatedButton(
            onPressed: () {
              UserService userService = UserService();
              userService.findAll().then((user) {
                print(user);
              });
            },
            child: const Text('查所有')),
        ElevatedButton(
            onPressed: () {
              UserService userService = UserService();
              userService.findBy({"name": "王五"}).then((user) {
                print(user);
              });
            },
            child: const Text('查条件')),
        ElevatedButton(
            onPressed: () {
              UserService userService = UserService();
              userService.findPage(page: 1, pageSize: 2).then((user) {
                print(user);
              });
            },
            child: const Text('查翻页')),
      ]),
    );
  }
}
